home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / inter54e.zip / INTSUM16.ZIP / MSGS.CPP < prev    next >
C/C++ Source or Header  |  1996-10-13  |  6KB  |  191 lines

  1. //********************************************************************
  2. //  MSGS.CPP - Message and help display functions                     
  3. //                                                                    
  4. //  Copyright (c) 1996 Daniel D. Miller                               
  5. //                                                                    
  6. //  Last Update:  08-31-95 10:10pm                                    
  7. //                                                                    
  8. //  Compile with makefile                                             
  9. //                                                                    
  10. //********************************************************************
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <time.h>
  16. #include "intsum.hpp"
  17. #include "keycodes.h"
  18. // #include <memcheck.h>
  19.  
  20. //*****************************************************************
  21. char* help_str[] = {
  22. Version,
  23. "                   A viewer for Ralf Brown's Interrupt List.         ",
  24. " ",
  25. " Keyboard commands: ",
  26. "  F1, h : This help screen ",
  27. "  F2, s : Search for string ",
  28. "  F3, r : Repeat last search ",
  29. "  F4, t : Save selected topic to a file. (from Ref list only) ",
  30. "  Enter : In reference listing, display detained info on current item. ",
  31. "  Esc   : Exit from program (in reference listing), ",
  32. "          Return to reference listing (in detail listing) ",
  33. " ",
  34. " The first time INTSUM is executed, it will create its custom index file",
  35. " before entering listing mode.  This brief operation will only occur once. ",
  36. " ",
  37. " This program is released as Freeware, though I retain copyright on it.",
  38. " It may be distributed freely.  No money may be charged for it except ",
  39. " reasonable media distribution fees.  To contact the author with bugs, ",
  40. " comments or suggestions, use Internet or SnailNet: ",
  41. " ",
  42. "     Internet:  derelict@netcom.com",
  43. "     SnailNet:  Daniel D. Miller ",
  44. "                36355 BridgePointe Drive",
  45. "                Newark, CA  94560",
  46.    0 } ;
  47.  
  48. void display_help(void)
  49.    {
  50.    clear_display(HELP_TEXT) ;
  51.    unsigned j = 0 ;
  52.    while (help_str[j] != 0) 
  53.       {
  54.       dprints(1, j, HELP_TEXT, help_str[j]) ;
  55.       j++ ;
  56.       }
  57.    get_key() ;
  58.    }
  59.  
  60. //*****************************************************************
  61. //  This will display the message pointed to by msg_str,
  62. //  wait for user input (displaying such on the message line),
  63. //  store the user input in global string srchstr[],
  64. //  then restore the message-line text when done.
  65. //  It returns the 0 on successful completion, Key_ESC on escape.
  66. //*****************************************************************
  67. //lint -e743
  68. const char CURSOR_ON  = '■' ;
  69. const char CURSOR_OFF = ' ' ;
  70. const clock_t BLINK_RATE = 300 ;
  71.  
  72. unsigned message_read(char* msg_str, char* instr)
  73.    {
  74.    //  display message for user
  75.    dprints(0, 2, MESSAGE, msg_str) ;
  76.  
  77.    //  fill remainder of line with input color
  78.    unsigned mlen = strlen(msg_str) ;
  79.    unsigned slen = 79 - mlen ;
  80.    spaces[slen] = 0 ;   //  terminate the spaces string at required length
  81.    dprints(mlen, 2, INPUT, spaces) ;
  82.    spaces[slen] = ' ' ; //  restore the spaces string
  83.    unsigned spos = mlen ;  //  data position on screen
  84.  
  85.    //  initialize cursor
  86.    int curmode = 1 ;
  87.    dprintc(spos, 2, INPUT, CURSOR_ON) ;
  88.    clock_t clk_time = clock() + BLINK_RATE ;
  89.  
  90.    //  get user input
  91.    unsigned mpos = 0 ;  //  data position in instr
  92.    unsigned indata ;
  93.    int done = 0 ;
  94.    while (!done) 
  95.       {
  96.       if (key_hit()) 
  97.          {
  98.          //curmode = 0 ;
  99.          dprintc(spos, 2, INPUT, CURSOR_OFF) ;
  100.          indata = get_key() ;
  101.          switch (indata) 
  102.             {
  103.             case Key_ESC:
  104.                //  turn off cursor
  105.                curmode = 0 ;
  106.                dprintc(spos, 2, INPUT, CURSOR_OFF) ;
  107.                done = -1 ;
  108.                break;
  109.  
  110.             case Key_ENTER:
  111.                *(instr+mpos) = 0 ;  //  NULL-terminate the string
  112.                done = 1 ;
  113.                indata = 0 ;
  114.                break;
  115.  
  116.             case Key_BSPACE:
  117.                if (mpos > 0) 
  118.                   {
  119.                   mpos-- ;
  120.                   *(instr+mpos) = 0 ;  //  NULL-terminate the string
  121.                   dprintc(--spos, 2, INPUT, ' ') ;
  122.                   }
  123.                break;
  124.  
  125.             default:
  126.                //  this won't work for ALL characters, 
  127.                //  but it will work for normal ASCII chars.
  128.                char outchr = (char) (indata & 0x00FF) ;
  129.                if (mpos < slen) 
  130.                   {
  131.                   *(instr+mpos) = outchr ;
  132.                   mpos++ ;
  133.                   dprintc(spos++, 2, INPUT, outchr) ;
  134.                   }
  135.                break;
  136.             }
  137.          //curmode = 1 ;
  138.          dprintc(spos, 2, INPUT, CURSOR_ON) ;
  139.          // clk_time = clock() + BLINK_RATE ;
  140.          }  //  if a key was pressed, read it
  141.  
  142.       //  If no key is pressed, update cursor
  143.       else 
  144.          {
  145.          if (clock() > clk_time) 
  146.             {
  147.             if (curmode == 0) 
  148.                {
  149.                curmode = 1 ;
  150.                dprintc(spos, 2, INPUT, CURSOR_ON) ;
  151.                clk_time = clock() + BLINK_RATE ;
  152.                }
  153.             else 
  154.                {
  155.                curmode = 0 ;
  156.                dprintc(spos, 2, INPUT, CURSOR_OFF) ;
  157.                clk_time = clock() + BLINK_RATE ;
  158.                }
  159.             }
  160.          }
  161.       }
  162.  
  163.    //  restore the message line to normal data
  164.    dprints(0, 2, LOGO, header) ;
  165.    return indata ;   //lint !e644
  166.    }
  167.  
  168. //*****************************************************************
  169. //  This will display the message pointed to by msg_str,
  170. //  wait for user keystroke,
  171. //  then restore the message-line text.
  172. //*****************************************************************
  173. void message_show(char* msg_str)
  174.    {
  175.    //  display message for user
  176.    dprints(0, 2, MESSAGE, msg_str) ;
  177.  
  178.    //  fill remainder of line with input color
  179.    unsigned mlen = strlen(msg_str) ;
  180.    unsigned slen = 79 - mlen ;
  181.    spaces[slen] = 0 ;   //  terminate the spaces string at required length
  182.    dprints(mlen, 2, MESSAGE, spaces) ;
  183.    spaces[slen] = ' ' ; //  restore the spaces string
  184.  
  185.    get_key() ;
  186.    //  restore the message line to normal data
  187.    dprints(0, 2, LOGO, header) ;
  188.    }
  189.  
  190.  
  191.